/*给相应的链接添加链接地址*/
var allBuildQALink = function(record) {
    //WebSite.debug(record.status);
    var adopt=record.adopt;
    var status=record.status;
   // var pk_answer=record.pk_sool_answer;
    var pk_question=record.pk_sool_question;
    if (adopt == WebSite.yes_adopt && status == WebSite.askerSolved ) {
        //已采纳已解决
        return WebSite.AskerSolvedPage.url + "&pk_question=" + pk_question;
    } else if (adopt == WebSite.no_adopt && status == WebSite.askerWaitToHandle) {
        //未采纳待处理
        if(record.isZhuiWen == WebSite.yes_zhuiwen){
            return WebSite.ReplayerHandlingPage.url + "&pk_question=" + pk_question;
        }
        return WebSite.UnAdoptHandlingPage.url +  "&pk_question=" + pk_question;
    } else {
        //未采纳，未解决

        //未采纳已解决
        return WebSite.AskerSolvedPage.url  + "&pk_question=" + pk_question;
    }
};

/*查询所有的回答*/
var findAll = function(pageno){
    if(pageno == null){
        pageno = 1;
    }
    $.ajax({
        url:WebSite.MyAnswerListPage.myanswer_list_pageno,
        type:"POST",
        data: {"pageno" : pageno,"methodname":'findAll'},
        dataType:"json",
        success:function(resulData){
            var data = resulData.resultData;
            for (var i = 0, len = data.length; i < len; i++) {
                var record = data[i];
                record.qa_link = allBuildQALink(record);
            }
            var pagemess=resulData.pagemess;
            $('#pagemes').html(pagemess);
            var myTemplate = Handlebars.compile($("#article_template").html());
            $("#myAnswerList").html(myTemplate(data));

        },
    });
}

/*查询生成所有的已采纳的回答*/
var Adopt = function(pageno){
    if(pageno == null){
        pageno = 1;
    }
    var params = $.param({
        "adopt": 1
    }, true);
    $.ajax({
        url:WebSite.MyAnswerListPage.myanswer_list_pageno_adopt1 + "&" + params,
        type:"POST",
        data: {"pageno" : pageno,"methodname":'Adopt'},
        dataType:"json",
        success:function(resulData){
            var data = resulData.resultData;
            for (var i = 0, len = data.length; i < len; i++) {
                var record = data[i];
                record.qa_link = allBuildQALink(record);
            }
            var pagemess=resulData.pagemess;
            $('#pagemes').html(pagemess);
            var myTemplate = Handlebars.compile($("#article_template").html());
            $("#myAnswerList").html(myTemplate(data));

        },
    });
}

/*查询未采纳的回答*/
var unAdopt = function(pageno){
    if(pageno == null){
        pageno = 1;
    }
    var params = $.param({
        "adopt" : 0
    },true);
    $.ajax({
        url:WebSite.MyAnswerListPage.myanswer_list_pageno_adopt0 + "&" + params,
        type:"POST",
        data: {"pageno" : pageno,"methodname":'unAdopt'},
        dataType:"json",
        success:function(resulData){
            var data = resulData.resultData;
            for (var i = 0, len = data.length; i < len; i++) {
                var record = data[i];
                record.qa_link = allBuildQALink(record);
            }
            var pagemess=resulData.pagemess;
            $('#pagemes').html(pagemess);
            var myTemplate = Handlebars.compile($("#article_template").html());
            $("#myAnswerList").html(myTemplate(data));

        },
    });
}


/*生成待处理的回答*/
var pending = function(pageno){
    if(pageno == null){
        pageno = 1;
    }
    var params = $.param({
        "status" : 1
    },true);
    $.ajax({
        url:WebSite.MyAnswerListPage.myanswer_list_pageno_status1,
        type:"POST",
        data: {"pageno" : pageno,"methodname":'pending'},
        dataType:"json",
        success:function(resulData){
            var data = resulData.resultData;
            for (var i = 0, len = data.length; i < len; i++) {
                var record = data[i];
                record.qa_link = WebSite.ReplayerHandlingPage.url + "&pk_question=" + record.pk_sool_question_farther + "&pk_sool_question_son=" + record.pk_sool_question_son;
            }
            var pagemess=resulData.pagemess;
            $('#pagemes').html(pagemess);
            var myTemplate = Handlebars.compile($("#answer_template").html());
            $("#myAnswerList").html(myTemplate(data));

        },
    });
}

/*根据对应的锚点加载不同的内容*/

/*根据对应的锚点加载不同的内容*/
var queryDataByStatus_answer = function() {
    var status_type = window.location.hash;
    WebSite.debug("queryDataByStatus这个方法："+status_type);
    if (status_type == "") {
        $("#subMyQuestionList li").removeClass("am-active");
        $("#a-all").toggleClass("am-active");
        findAll();
    }
    else if (status_type == "#s1") {
        $("#subMyQuestionList li").removeClass("am-active");
        $("#a-adopt").toggleClass("am-active");
        tobeanswered();
    }  else if (status_type == "#s2") {
        $("#subMyQuestionList li").removeClass("am-active");
        $("#a-unadopt").toggleClass("am-active");
        pending();
    }  else if (status_type == "#s3") {
        $("#subMyQuestionList li").removeClass("am-active");
        $("#a-handling").toggleClass("am-active");
        alreadysolved();
    }

};


/*格式化时间*/
Handlebars.registerHelper("transdate", function(str,options){
    return new Date(parseInt(str)).toLocaleString();
});

/*精华问题的加载*/
var similarQuestion = function(){
    $.ajax({
        url:WebSite.MyQuestionListPage.essencequestion_list,
        type:"POST",
        data:{"count":10},
        dataType:"json",
        success:function(resultData){
            var data = resultData.resultData;
            for (var i = 0, len = data.length; i < len; i++) {
                var record = data[i];
                var pk_sool_question = record.pk_sool_question;
                record.qa_link = WebSite.AskerSolvedPage.url + "&pk_question="+pk_sool_question;
            }
            var myTemplate = Handlebars.compile($("#li_template").html());
            $("#xsQuestionList").html(myTemplate(data));
        },
        error:function(){
            alert("相似问题未加载");
        }
    });

};